<?php if($products == FALSE): ?>
<div>Khong co san pham trong muc nay</div>
<?php endif;?>
<?php foreach ($products as $product): ?>
<div class="product">
    <div class="product-title" style="color: red; margin-left: 10px">-<?php echo $product->name ?></div>
    <?php $i = 0; ?>
    <?php foreach (DistributorProduct::getProduct($product->id) as $distributor): ?>
        <?php if ($i < 3){ ?>
        <div class="distributor" id="<?php echo $distributor->distributor_id ?>" style="margin-left: 20px;">
            +<?php echo Users::model()->findByPk($distributor->distributor_id)->full_name ?> : <?php echo $distributor->unit_price ?>
            - <a href="javascript:;" class="add-to-cart" id="<?php echo $product->id ?>" rel="<?php echo $amount ?>">Add to cart</a>
        </div>
        <?php }else{ ?>
        <div class="distributor-<?php echo $product->id?>" style="margin-left: 20px; display: none">
            <?php echo Users::model()->findByPk($distributor->distributor_id)->full_name ?> : <?php echo $distributor->unit_price ?>
            - <a href="javascript:;" class="add-to-cart" id="<?php echo $product->id ?>" rel="<?php echo $amount ?>">Add to cart</a>
        </div>
        <?php } ?>
        <?php $i++ ?>
        <?php endforeach; ?>
    
    <?php if ($i >= 3): ?>
    <div><a  class="next" id="<?php echo $product->id?>">Xem thêm...</a></div>
    <?php endif ?>
</div>
<?php endforeach; ?>
<script>
    
    $('.next').click(function(){
        var id = $(this).attr('id');
        $('.distributor-' + id).css('display', 'block');
    });
    var request; 
    $('.add-to-cart').click(function(){
             $.post(
                 base_url+'?r=shop/shop/addToCart',               
                {
                    'distributor':$(this).parent().attr('id'), 
                    'product_id' : $(this).attr('id'), 
                    'amount' : $(this).attr('rel')
                }
                )
                .success(function(){ alert('ok');});
     
        });
</script>
